#pragma once

#include "Object/Object.h"
#include "AssetPath.h"

#include "AssetObject.m.h"

class RTexture2D;
//every asset is a object
//all objects in a asset is subobject of the asset object
RCLASS()
class WHENGINE_API RAssetObject: public RObject
{
    ROBJECT

public:
    RAssetObject();

    TWeakObjectPtr<RObject> MainObject=nullptr;

    TWeakObjectPtr<RObject> EditInfoObject=nullptr;

    //该资产是否一直在内存中
    //如果为true,不会被其他资产依赖
    bool bAlwaysInMemory=false;

    //thumbnail of the asset
    // might be null, even this asset have thumbnail, because thumbnail is not nessary
    TWeakObjectPtr<RTexture2D> Thumbnail=nullptr;

    void SetAssetPath(const SAssetPath& InPath)
    {
        Path=InPath;
        SetNodeName(CreateName(Path));
        assert(CreatePath(Path)==GetPath());
    }

    //create name of asset object
    static CString CreateName(const SAssetPath& InPath);

    static CString CreateName(
        CClass * InAssetType
        ,const CString& InPackageName
        , const CString& InFolderPathInPackage
        , const CString& InAssetName
        );


    //create path of asset object
    static CString CreatePath(const SAssetPath& InPath);
    
    //create path of asset object
    static CString CreatePath(
        CClass * InAssetType
        ,const CString& InPackageName
        , const CString& InFolderPathInPackage
        , const CString& InAssetName
        );

    static CString CreateThumnailPath(const SAssetPath& InPath);

    virtual const SAssetPath* GetAssetPath() const override;
protected:
    //path when load from asset file
    SAssetPath Path;

public:
    //找到指定对象的资产对象
    //如果该对象不存在对应的资产对象，则返回空
    static TSharedObjectPtr<RAssetObject> GetAssetObject(TSharedObjectPtr<RObject> InObject);

};
